package 笔试.腾讯;

import java.util.Scanner;

/**
 * @author:谢君臣
 * @Date:2021/9/5-17:35
 * @version:1.0
 * @function:
 */
public class Main9501 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String n = scanner.nextLine();
        String line = scanner.nextLine();
        int a=0,b=0;
        int res = 0;
        for (int i = 0; i < line.length(); i++) {
            if (line.charAt(i)=='0')a++;
            else b++;
        }
        for (int i = 1; i <=Math.max(a,b) ; i++) {
            res += i;
        }
        if (a>b){
            int i =0,temp =0;
            while (line.charAt(i)=='1'){i++;temp+=i;}
            res = res+temp;
            i =0;temp =0;
            while (line.charAt(line.length()-1-i)=='1'){i++;temp+=i;}
            res = res+temp;
        }else {
            int i =0,temp =0;
            while (line.charAt(i)=='0'){i++;temp+=i;}
            res = res+temp;
            i =0;temp =0;
            while (line.charAt(line.length()-1-i)=='0'){i++;temp+=i;}
            res = res+temp;
        }
        System.out.println(res);
    }

    //20
     //       11111000111011101100
}
